package com.yyzw.activiti.modeler.controller;

import com.github.abel533.echarts.axis.CategoryAxis;
import com.github.abel533.echarts.axis.ValueAxis;
import com.github.abel533.echarts.code.Tool;
import com.github.abel533.echarts.code.Trigger;
import com.github.abel533.echarts.data.Data;
import com.github.abel533.echarts.data.PieData;
import com.github.abel533.echarts.json.GsonOption;
import com.github.abel533.echarts.series.Bar;
import com.github.abel533.echarts.series.Gauge;
import com.github.abel533.echarts.series.Line;
import com.github.abel533.echarts.series.Pie;
import com.github.abel533.echarts.series.gauge.Detail;
import com.yyzw.activiti.modeler.model.ChatsVo;
import com.yyzw.activiti.modeler.model.ResponseVo;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("charts")
public class EchartsController {

    @RequestMapping("showEchartPage")
   public ModelAndView showEchartPage(HttpServletRequest request,ModelAndView modelAndView)throws Exception{
       modelAndView.setViewName("echarts/business_charts");
       return modelAndView;
   }

   @RequestMapping("par")
   public ResponseVo parCharts(HttpServletRequest request)throws Exception{
       GsonOption option = new GsonOption();
       option.title().text("企业历年纳税统计");
       option.tooltip().trigger(Trigger.axis);//点击上去有浮窗效果
       option.xAxis(new CategoryAxis().data("2018年","2019年"));
       option.yAxis(new ValueAxis());
       Bar bar = new Bar();
       bar.data(50000,307026);
       option.series(bar);
       System.out.println(option);
       System.out.println(option.toPrettyString());
       System.out.println(option.toString());
       return new ResponseVo(true,"加载成功", option.toString());
   }

   @RequestMapping("bar")
   public ResponseVo barCharts(HttpServletRequest request)throws Exception{
       GsonOption option = new GsonOption();
       option.title("企业纳税比例");
       option.tooltip().trigger(Trigger.item).formatter("{a/*option.legend(\"财政税款\",\"印花税\",\"个人税\",\"企业增值税\");*/} <br/>{b} : {c} ({d}%)");

       Pie pie1 = new Pie();
       pie1.setName("企业纳税情况统计");
       PieData pieData1 =new PieData("财政税款",300000);
       PieData pieData2 =new PieData("印花税",50000);
       PieData pieData3 =new PieData("个人税",1000);
       PieData pieData4 =new PieData("企业增值税",80000);
       List<PieData> list=new ArrayList<>();
       list.add(pieData1);
       list.add(pieData2);
       list.add(pieData3);
       list.add(pieData4);
       pie1.setData(list);
       option.series(pie1);
       return new ResponseVo(true,"加载成功",option.toString());
   }

   @RequestMapping("line")
   public ResponseVo lineCharts(HttpServletRequest request) throws Exception{
       GsonOption option = new GsonOption();
       option.title("2019年企业纳税分月统计");
       option.tooltip().trigger(Trigger.axis);
       option.legend("本年","去年");
       option.xAxis(new CategoryAxis().boundaryGap(false).data("一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"));
       option.yAxis(new ValueAxis());
       Line line1 =new Line("本年");
       line1.data(3388,269957,3900,81);
       Line line2 =new Line("去年");
       line2.data(31834,98751,49925,112024,53815,13982,180923,47102,45366,6685,46001,42478);
       option.series(line1,line2);
       return new ResponseVo(true,"加载成功",option.toString());
   }

    @RequestMapping("swwShow")
   public ModelAndView swwChartsShow(HttpServletRequest request,ModelAndView modelAndView) throws Exception{
     modelAndView.setViewName("echarts/sww_charts");
     return modelAndView;
   }

    @RequestMapping("swwcharts")
    public ResponseVo swwCharts(HttpServletRequest request, ChatsVo chatsVo) throws  Exception{
        GsonOption option = new GsonOption();
        if(chatsVo.getType().equalsIgnoreCase("1")){
            option.title("国际贸易资金扶持使用情况",chatsVo.getYear()+"年度");
            option.tooltip().trigger(Trigger.item).formatter("{a} <br/>{b} : {c} ({d}%)");
            option.legend("已使用资金","未使用资金");
            Pie pie = new  Pie();
            pie.setName("项目资金使用情况");
            PieData pieData1 = new PieData("已使用资金", 1000);
            PieData pieData2 = new PieData("未使用资金", 2000);
            List<PieData> list = new ArrayList<PieData>();
            list.add(pieData1);
            list.add(pieData2);
            pie.setData(list);
            //pie.setItemStyle();
            option.series(pie);
        }else{
            option.title("国际贸易资金扶持使用情况",chatsVo.getYear()+"年度");
            option.tooltip().formatter("{a} <br/>{b} : {c}%");
            option.toolbox().show(true).feature(Tool.mark, Tool.restore, Tool.saveAsImage);
            option.series(new Gauge("业务指标").detail(new Detail().formatter("{value}%")).data(new Data("资金使用率", 75)));
        }
        System.out.println(option.toString());
        return new ResponseVo(true,"加载成功",option.toString());
   }
}
